const namespaced = true;
const state = {
  username: JSON.parse(localStorage.getItem("userInfo"))?.username,
  avatar: JSON.parse(localStorage.getItem("userInfo"))?.avatar,
  userId: JSON.parse(localStorage.getItem("userInfo"))?.userId,
};
// getters
const getters = {
  getUsername: (state) => state.username,
  getAvatar: (state) => state.avatar,
  getUserId: (state) => state.userId,
};

const actions = {
  setUsername({ commit }, payload) {
    commit("SET_USERNAME", payload);
  },
  setAvatar({ commit }, payload) {
    commit("SET_AVATAR", payload);
  },
  setUserId({ commit }, payload) {
    commit("SET_USER_ID", payload);
  },
};

const mutations = {
  SET_USERNAME(state, payload) {
    state.username = payload;
  },
  SET_AVATAR(state, payload) {
    state.avatar = payload;
  },
  SET_USER_ID(state, payload) {
    state.userId = payload;
  },
};

export default {
  namespaced,
  state,
  getters,
  actions,
  mutations,
};
